package com.rub.prajna.av.domain

import javafx.application.Application
import javafx.beans.binding.Bindings
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.media.Media
import javafx.scene.media.MediaPlayer
import javafx.scene.media.MediaView
import javafx.stage.Stage
import java.io.File

class JavaFXMedia : Application() {

    @Throws(Exception::class)
    override fun start(primaryStage: Stage) {
        //Initialising path of the media file, replace this with your file path
        val path = "D:\\video\\周边逛逛碰上街边举办,海上世界周末演唱会.mp4"

        //Instantiating Media class
        val media = Media(File(path).toURI().toString())

        //Instantiating MediaPlayer class
        val mediaPlayer = MediaPlayer(media)

        //Instantiating MediaView class
        val mediaView = MediaView(mediaPlayer)
        /*val width = mediaView.fitWidthProperty()
        val height = mediaView.fitHeightProperty()
        width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width"))
        height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height"))*/
        mediaView.fitWidth = 320.0
        mediaView.fitHeight = 240.0
        mediaView.isPreserveRatio = false

        mediaView.translateX = mediaView.fitWidth / 2 + 200
        mediaView.translateY = mediaView.fitHeight / 2 + 200
        mediaView.scaleX = 2.0
        mediaView.scaleY = 2.0

        //by setting this property to true, the Video will be played
        mediaPlayer.isAutoPlay = true

        //setting group and scene
        val root = Group()
        root.children.add(mediaView)
        val scene = Scene(root, 500.0, 400.0)
        primaryStage.scene = scene
        primaryStage.title = "Playing video"
        primaryStage.show()
    }

    companion object{
        @JvmStatic
        private fun main(args: Array<String>) {
            launch(*args)
        }
    }


}